
<?php

//echo "<table style='border: solid 1px black;'>";
//echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th><th>Email</th><th>Reg date</th></tr>"; -

$servername = "localhost";
$username = "ospms";
$password = "ospms";
$dbname = "OSPMS";


class TableRows extends RecursiveIteratorIterator {
    function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);
    }

    function current() {
//        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
        return " ".parent::current();
    }

    function beginChildren() {
//        echo "<tr>";
    }

    function endChildren() {
//        echo "</tr>" . "\n";
    }
}


try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$select = $conn->query('SELECT * FROM user_uploaded_files');

$total_column = $select->columnCount();
//var_dump($total_column);

for ($counter = 0; $counter <= $total_column; $counter ++) {
    $meta = $select->getColumnMeta($counter);
    $column[] = $meta['name'];
}
//print_r($column);

//    $stmt = $conn->prepare("SELECT * FROM user_uploaded_files");
    $stmt = $conn->prepare("SELECT file_location,file_name,user_id,file_id,folder_id FROM user_uploaded_files");
    $stmt->execute();
    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
        echo $v;
    }

    }
catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
$conn = null;
?> 
